#pragma once
#include "../domain/Map.h"
#include "GraphDrawer.h"
#include "PathDrawer.h"
#include "../business/GraphManager.h"

class CarManager {
private:

	static int MAX_SPEED;
	static int MIN_SPEED;

	SDL_Surface* car;
	SDL_Surface* carUp;
	SDL_Surface* carDown;
	SDL_Surface* carRight;
	SDL_Surface* carLeft;
	SDL_Surface* speedInfraction;
	SDL_Surface* speedLim;
	SDL_Surface* wrongDirection;
	SDL_Surface* giroIzq;
	SDL_Surface* giroDer;
	SDL_Surface* mantenerDir;
	SDL_Surface* llego;
	SDL_Surface* vel;
	SDL_Surface* negro;
	SDL_Surface* km;
	SDL_Surface* zero;
	SDL_Surface* one;
	SDL_Surface* two;
	SDL_Surface* three;
	SDL_Surface* four;
	SDL_Surface* five;
	SDL_Surface* six;
	SDL_Surface* seven;
	SDL_Surface* eigth;
	SDL_Surface* nine;

	SDL_Surface* screen;
	SDL_Surface* previous;
	SDL_Surface* panel;
	SDL_Surface* withNoPanel;
	SDL_Surface* speedSurface;
	Viewport* viewport;

	int carX;
	int carY;
	int speed;
	int currentDirection;
	int nextDirection;
	Vertex* vNext;
	Edge* eActual;
	bool wrongDir;

public:

	static int UP;
	static int DOWN;
	static int LEFT;
	static int RIGHT;
	static int STRAIGHT;

	CarManager(SDL_Surface* screen, Viewport* viewport);
	virtual ~CarManager();

	int getCarX() const;
	int getCarY() const;
	Vertex* getVNext() const;
	Edge* getActualEdge() const;

	void calcInitPosition(float& carX, float& carY, Map* map, string idEdgeFrom, int addFrom, string idEdgeTo,GraphDrawer* drawer);
	bool carAtVertex(float vX, float vY);
	void drawCar(int x, int y, bool firstTime);
	void drawAll(List* vertexListPath, Vertex* vertex/*, Vertex* additionalVertex*/);
	void drawPanel(bool firstTime, List* vertexListPath, Vertex* vertex/*, Vertex* additionalVertex*/);
	void drawSpeed();
	void drawNextAction(List* vertexListPath, Vertex* vertex/*, Vertex* additionalVertex*/);
	void turn(int key);
	void speedUp();
	void speedDown();
	bool checkSpeedLimit();
	bool checkSpeedInfraction();
	void timePasses();
	void updateCarPosition(Map* map,GraphManager* graphManager);
	int getSleep();
	void drawSurfaceAt(SDL_Surface* from, int x, int y, SDL_Surface* to);	
};